import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Button here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public abstract class Button extends Actor
{
    protected int xPos;
    protected int yPos;
    
    public Button(int x,int y)
    {
        xPos=x;
        yPos=y;
    }
    
    public void act() 
    {
        if(isMouseOver())
        setLocation(xPos,yPos-5);
        else
        setLocation(xPos,yPos);     
    }    
    
    public boolean isMouseOver()
    {
        MouseInfo mouse=getMouse();
        
        if(mouse==null)
        return(false);
        
        int xIni,yIni,xFin,yFin;
        
        xIni=xPos-getImage().getWidth()/2;
        xFin=xPos+getImage().getWidth()/2;
        yIni=yPos-getImage().getHeight()/2;
        yFin=yPos+getImage().getHeight()/2;
        
        if(mouse.getX()>xIni && mouse.getX()<xFin && mouse.getY()>yIni && mouse.getY()<yFin)
        return(true);
        else
        return(false);
    }
    
    public boolean clicked()
    {
        if(getMouse().getButton()==1 && getMouse().getClickCount()==1)
        return(true);
        else
        return(false);
    }
    
    public MouseInfo getMouse()
    {
        return(Greenfoot.getMouseInfo());
    }
        
}
